<template>
  <!--  OEM基盘任务定义 -->
  <div>
    <!-- <TopFilter
      :list="topFilterList"
      :cols="4"
      labelWidth="100"
      @filterChange="changeHandle"
      @onCollapse="collapseHandle"
    ></TopFilter> -->
    <!-- <div class="father">
      <FormPanel
        ref="formPanel"
        :list="formList"
        :cols="1"
        :formType="type"
        labelWidth="110"
        :isSubmitBtn="false"
        @formChange="formChangeHandle"

      />
      <template class="son" >
        <el-button class="son" @click="saveDialog" type="primary">保 存</el-button>
      </template>
    </div> -->

    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :isSelectColumn='false'
      :onColumnsChange="columns => this.columns = columns"
    >
      <!-- <template slot="controls" slot-scope="props">
        <el-button size="small" type="primary" icon="el-icon-plus" @click="addHandle">新增</el-button>
      </template> -->
    </FilterTable>
    <BaseDialog
      :visible.sync="visible"
      :title="dialogTitle"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <baseModel :type="handleType" :rowData="formData" @close="closeHandler" />
    </BaseDialog>
  </div>
</template>

<script>
import {
  searchInvalidClues,
  saveDays,
  editInvalidClues
 } from '@/api/potenCus/basedata/custTaskOEM';
import { dictionary } from '@/utils/dictMixin';
import baseModel from './baseModel';
export default {
  name: 'custTaskOEM',
  mixins: [dictionary],
  components: {
    baseModel
  },
  props: {
    type: {
      type: String,
      default: 'save'
    },
    rowData: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      // topFilterList: this.createTopFilters(),
      fetchParams: {},
      visible: false,
      dialogTitle: '',
      fetchApi: searchInvalidClues,
      columns: this.createTableColumns(),
      // formList: this.createFormList(),
      handleType: '',
      formData: {},
      conf:{ add: '设置', edit: '编辑', save:'保存' },
      page: {
        pageNum: 1,
        currentPage: 1,
        pageSize: 100,
        limit: 100,
      },
      // days: this.getDays()
    };
  },
  created(){
  },
  methods: {
    async getDays(){
      const res = await searchInvalidClues()
      console.log('res', res)

    },
    createTopFilters() {
      return [ ];
    },
    // createFormList() {
    //   return [
    //     {
    //       type: 'INPUT_NUMBER',
    //       label: '可提前跟进天数',
    //       fieldName: 'days',
    //       placeholder: '',
    //       initialValue: 7,
    //       style: { width: '200px' },
    //       rules: [{ required: true, message: '请填写跟进间隔天数', trigger: 'blur' }]
    //     },
    //   ];
    // },
    createTableColumns() {
      return [
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 60,
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.editHandle(props.row)}>
                  编辑
                </el-button>
              </div>
            );
          }
        },
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '基盘客户等级',
          dataIndex: 'intentLevel',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('7049'),
          render: props => {
            return <span>{this.createDictText(props.row.intentLevel, '7049')}</span>;
          }
        },
        {
          title: '描述',
          dataIndex: 'taskContent',
          sorter: true,
          filter: true,
          width: 220,
          filterType: 'input',
        },
        {
          title: '间隔天数',
          dataIndex: 'intervalDays',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '是否有效',
          dataIndex: 'isValid',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          render: props => {
            return <span>{this.createDictText(props.row.isValid, '1004')}</span>;
          }
        },
      ];
    },
    // addHandle() {
    //   this.handleType = 'add';
    //   this.showHandler();
    // },
    editHandle(row) {
      console.log('row',row)
      this.handleType = 'edit';
      this.formData = row;
      this.showHandler();
    },
    showHandler() {
      this.dialogTitle = `基盘任务${this.conf[this.handleType]}`;
      this.visible = true;
    },
    // async saveDialog() {
    //   this.$refs.formPanel.SUBMIT_FORM();
    //   console.log('save',this.saveData  )
    //   if (this.saveData !== null) {
    //     let res = {};
    //     if (this.type === 'save'){
    //       res = await saveDays(this.saveData)
    //     }
    //     if (res.resultCode === 200) {
    //       this.closeDialog('refresh');
    //       this.$message.success("保存成功!");
    //     }

    //   }
    // },
    closeDialog(param) {
      this.$emit('close', false, param);
    },
    // changeHandle(val) {
    //   this.fetchParams = Object.assign({}, val);
    // },
    // formChangeHandle(val) {
    //   this.saveData = val;
    // },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    closeHandler(val, type) {
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    }
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  created() {
  }
};
</script>

<style lang="less" scoped>
.father{
  position: relative;
  margin: 10px 0 0;
}
.son{
  position: absolute;
  top: 0;
  left: 340px;
  z-index: 10;
}
</style>
